package view.component.weapon
{
	import enums.main.UISize;
	
	import feathers.controls.Label;
	import feathers.controls.List;
	import feathers.controls.Scroller;
	import feathers.controls.renderers.DefaultListItemRenderer;
	import feathers.controls.renderers.IListItemRenderer;
	import feathers.data.ListCollection;
	import feathers.layout.HorizontalLayout;
	import feathers.layout.TiledRowsLayout;
	import feathers.layout.VerticalLayout;
	
	import model.vo.weapon.BaseBowGunWeaponVo;
	
	import util.ItemUtil;
	import util.WeaponUtil;
	
	/**
	 * 弩类武器详细信息基类
	 * @author £iang
	 * 
	 */	
	public class BaseBowGunWeaponDetailView extends BaseWeaponDetailView
	{
		//-----------------------------
		// variables
		//-----------------------------
		
		/** 增加攻击标题 */
		public var addAttackTitle:Label;
		/** 增加攻击信息 */
		public var addAttackLabel:Label;
		/** 装填速度标题 */
		public var reloadSpeedTitle:Label;
		/** 装填速度信息 */
		public var reloadSpeedLabel:Label;
		/** 反动标题 */
		public var reactionTitle:Label;
		/** 反动信息 */
		public var reactionLabel:Label;
		/** 弹道偏移标题ok */
		public var offsetTitle:Label;
		/** 弹道偏移信息ok */
		public var offsetLabel:Label;
		/** 特殊弹种标题 */
		public var specialBulletTitle:Label;
		/** 特殊弹种信息 */
		public var specialBulletLabel:Label;
		/** 特殊弹种列表 */
		public var specialBulletList:List;
		/** 子弹列表标题 */
		public var bulletTitle:Label;
		/** 子弹列表信息 */
		public var bulletLabelVec:Vector.<Label>;
		/** 加攻击价格标题 */
		public var addAttackPriceTitle:Label;
		/** 加攻击价格信息 */
		public var addAttackPriceLabel:Label;
		/** 其他价格标题 */
		public var otherPriceTitle:Label;
		/** 其他价格信息 */
		public var otherPriceLabel:Label;
		/** 可变倍率镜头价格标题 */
		public var ratioMirrorPriceTitle:Label;
		/** 可变倍率镜头价格信息 */
		public var ratioMirrorPriceLabel:Label;
		/** 限制解除价格标题 */
		public var limitBreakPriceTitle:Label;
		/** 限制解除价格信息 */
		public var limitBreakPriceLabel:Label;
		
		
		//-----------------------------
		// properties
		//-----------------------------
		
		/** 增加攻击标题文字 */
		protected var _addAttackTitleText:String;
		/** 特殊弹种标题文字 */
		protected var _specialBulletTitleText:String;
		/** 加攻价格标题名 */
		protected var _addAttackPriceTitleText:String;
		/** 其他价格标题名 */
		protected var _otherPriceTitleText:String;
		
		/** 是否限解 */
		protected var _isLimitBreak:Boolean;
		
		/** specialBulletList数据 */
		protected var _listDataSpecialBullet:ListCollection;
		
		//-----------------------------
		// setter&getter
		//-----------------------------
		
		//-----------------------------
		// methods
		//-----------------------------
		
		/**
		 * 初始化函数 
		 * 
		 */		
		override protected function initialize():void
		{
			super.initialize();
			addAttackTitle = new Label();
			addAttackTitle.text = _addAttackTitleText;
			mainSC.addChild( addAttackTitle );
			
			addAttackLabel = new Label();
			addAttackLabel.textRendererProperties.isHTML = true;
			mainSC.addChild( addAttackLabel );
			
			reloadSpeedTitle = new Label();
			reloadSpeedTitle.text = "装填速度：";
			mainSC.addChild( reloadSpeedTitle );
			
			reloadSpeedLabel = new Label();
			mainSC.addChild( reloadSpeedLabel );
			
			reactionTitle = new Label();
			reactionTitle.text = "反动：";
			mainSC.addChild( reactionTitle );
			
			reactionLabel = new Label();
			mainSC.addChild( reactionLabel );
			
			offsetTitle = new Label();
			offsetTitle.text = "弹道偏移：";
			mainSC.addChild( offsetTitle );
			
			offsetLabel = new Label();
			mainSC.addChild( offsetLabel );
			
			specialBulletTitle = new Label();
			specialBulletTitle.text = _specialBulletTitleText;
			mainSC.addChild( specialBulletTitle );
			
			specialBulletLabel = new Label();
			mainSC.addChild( specialBulletLabel );
			
			var tileLayout:TiledRowsLayout = new TiledRowsLayout();
			tileLayout.useSquareTiles = false; 
			tileLayout.tileVerticalAlign = VerticalLayout.VERTICAL_ALIGN_TOP;
			tileLayout.tileHorizontalAlign = HorizontalLayout.HORIZONTAL_ALIGN_LEFT;
			tileLayout.verticalAlign = VerticalLayout.VERTICAL_ALIGN_TOP;
			tileLayout.horizontalAlign = HorizontalLayout.HORIZONTAL_ALIGN_LEFT;
			tileLayout.gap = 10 * this.dpiScale;
			
			specialBulletList = new List();
			mainSC.addChild( specialBulletList );
			specialBulletList.width = UISize.MAIN_W - 20 * this.dpiScale;
			specialBulletList.itemRendererProperties.labelField  = "label";
			specialBulletList.itemRendererFactory = specialBulletRenderFactroy;
			specialBulletList.hasElasticEdges = false;
			specialBulletList.scrollerProperties.scrollBarDisplayMode = Scroller.SCROLL_BAR_DISPLAY_MODE_NONE;
			specialBulletList.verticalScrollPolicy = Scroller.SCROLL_POLICY_OFF;
			specialBulletList.horizontalScrollPolicy = Scroller.SCROLL_POLICY_OFF;
			specialBulletList.height = ( UISize.ITEM_LIST_ITEM_H * 2 + 10 ) * this.dpiScale;
			specialBulletList.layout = tileLayout;
			
			bulletTitle = new Label();
			bulletTitle.text = "载弹情况：(蓝字：对应弹追加后的载弹量)";
			mainSC.addChild( bulletTitle );
			
			bulletLabelVec = new Vector.<Label>();
			
			for ( var i:int = 0; i < 22; i ++ )
			{
				var bulletLabel:Label = new Label();
				
				bulletLabel.textRendererProperties.isHTML = true;
				bulletLabelVec.push( bulletLabel );
				mainSC.addChild( bulletLabelVec[ i ] );
			}
			
			addAttackPriceTitle = new Label();
			addAttackPriceTitle.text = _addAttackPriceTitleText;
			mainSC.addChild( addAttackPriceTitle );
			
			addAttackPriceLabel = new Label();
			mainSC.addChild( addAttackPriceLabel );
			
			otherPriceTitle = new Label();
			otherPriceTitle.text = _otherPriceTitleText;
			mainSC.addChild( otherPriceTitle );
			
			otherPriceLabel = new Label();
			mainSC.addChild( otherPriceLabel );
			
			ratioMirrorPriceTitle = new Label();
			ratioMirrorPriceTitle.text = "可变倍率：";
			mainSC.addChild( ratioMirrorPriceTitle );
			
			ratioMirrorPriceLabel = new Label();
			mainSC.addChild( ratioMirrorPriceLabel );
			
			limitBreakPriceTitle = new Label();
			limitBreakPriceTitle.text = "限制解除：";
			mainSC.addChild( limitBreakPriceTitle );
			
			limitBreakPriceLabel = new Label();
			mainSC.addChild( limitBreakPriceLabel );
		}
		
		/**
		 * 绘制函数 
		 * 
		 */		
		override protected function draw():void
		{
			super.draw();
			
			addAttackTitle.x = 20 * this.dpiScale;
			addAttackTitle.y = 120 * this.dpiScale;
			addAttackLabel.x = 150 * this.dpiScale;
			addAttackLabel.y = 120 * this.dpiScale;
			
			criticalTitle.x = 20 * this.dpiScale;
			criticalTitle.y = 180 * this.dpiScale;
			criticalLabel.x = 150 * this.dpiScale;
			criticalLabel.y = 180 * this.dpiScale;
			
			slotTitle.x = 20 * this.dpiScale;
			slotTitle.y = 240 * this.dpiScale;
			slotLabel.x = 150 * this.dpiScale;
			slotLabel.y = 240 * this.dpiScale;
			
			reloadSpeedTitle.x = 20 * this.dpiScale;
			reloadSpeedTitle.y = 300 * this.dpiScale;
			reloadSpeedLabel.x = 150 * this.dpiScale;
			reloadSpeedLabel.y = 300 * this.dpiScale;
		
			reactionTitle.x = 270 * this.dpiScale;
			reactionTitle.y = 300 * this.dpiScale;
			reactionLabel.x = 350 * this.dpiScale;
			reactionLabel.y = 300 * this.dpiScale;
			
			offsetTitle.x = 20 * this.dpiScale;
			offsetTitle.y = 360 * this.dpiScale;
			offsetLabel.x = 150 * this.dpiScale;
			offsetLabel.y = 360 * this.dpiScale;
			
			specialBulletTitle.x = 20 * this.dpiScale;
			specialBulletTitle.y = 420 * this.dpiScale;
			specialBulletLabel.x = 20 * this.dpiScale;
			specialBulletLabel.y = 480 * this.dpiScale;
			specialBulletList.x = 20 * this.dpiScale;
			specialBulletList.y = 480 * this.dpiScale;
			
			bulletTitle.x = 20 * this.dpiScale;
			bulletTitle.y = 600 * this.dpiScale;
			
			var i:int;
			var curLabel:Label;
			var bulletTableW:Number = UISize.MAIN_W - 20 * this.dpiScale;
			
			for ( i = 0; i < 6; i ++ )
			{
				curLabel = bulletLabelVec[ i ];
				curLabel.x = 20 * this.dpiScale;
				curLabel.y = ( 660 + 60 * i ) * this.dpiScale;
				curLabel.width = bulletTableW * 0.35;
			}
			
			for ( i = 6; i < 12; i ++ )
			{
				curLabel = bulletLabelVec[ i ];
				curLabel.x = 20 * this.dpiScale + bulletTableW * 0.35;
				curLabel.y = ( 660 + 60 * ( i - 6 ) ) * this.dpiScale;
				curLabel.width = bulletTableW * 0.25;
			}
			
			for ( i = 12; i < 17; i ++ )
			{
				curLabel = bulletLabelVec[ i ];
				curLabel.x = 20 * this.dpiScale + bulletTableW * 0.6;
				curLabel.y = ( 660 + 60 * ( i - 12 ) ) * this.dpiScale;
				curLabel.width = bulletTableW * 0.2;
			}
			
			for ( i = 17; i < 22; i ++ )
			{
				curLabel = bulletLabelVec[ i ];
				curLabel.x = 20 * this.dpiScale + bulletTableW * 0.8;
				curLabel.y = ( 660 + 60 * ( i - 17 ) ) * this.dpiScale;
				curLabel.width = bulletTableW * 0.2;
			}
			
			addAttackPriceTitle.x = 20 * this.dpiScale;
			addAttackPriceTitle.y = 1020 * this.dpiScale;
			addAttackPriceLabel.x = 150 * this.dpiScale;
			addAttackPriceLabel.y = 1020 * this.dpiScale;
			
			otherPriceTitle.x = 30 * this.dpiScale + ( UISize.MAIN_W >> 1 );
			otherPriceTitle.y = 1020 * this.dpiScale;
			otherPriceLabel.x = 160 * this.dpiScale + ( UISize.MAIN_W >> 1 );
			otherPriceLabel.y = 1020 * this.dpiScale;
			
			ratioMirrorPriceTitle.x = 20 * this.dpiScale;
			ratioMirrorPriceTitle.y = 1080 * this.dpiScale;
			ratioMirrorPriceLabel.x = 150 * this.dpiScale;
			ratioMirrorPriceLabel.y = 1080 * this.dpiScale;
			
			limitBreakPriceTitle.x = 30 * this.dpiScale + ( UISize.MAIN_W >> 1 );
			limitBreakPriceTitle.y = 1080 * this.dpiScale;
			limitBreakPriceLabel.x = 160 * this.dpiScale + ( UISize.MAIN_W >> 1 );
			limitBreakPriceLabel.y = 1080 * this.dpiScale;
		}
		
		/**
		 * 调整部分组件 
		 * @param offsetY 插入某项后的Y偏移
		 * 
		 */		
		protected function drawPart():void
		{
			productTitle.x = 20 * this.dpiScale;
			productTitle.y = ( 1140 + insertOffset ) * this.dpiScale;
			productPriceLabel.x = 150 * this.dpiScale;
			productPriceLabel.y = ( 1140 + insertOffset ) * this.dpiScale;
			
			produceItemList.x = 150 * this.dpiScale;
			produceItemList.y = ( 1200 + insertOffset ) * this.dpiScale;
			
			strengthTitle.x = 20 * this.dpiScale;
			strengthTitle.y = ( 1440 + insertOffset ) * this.dpiScale;
			strengthPriceLabel.x = 150 * this.dpiScale;
			strengthPriceLabel.y = ( 1440 + insertOffset ) * this.dpiScale;
			
			strengthItemList.x = 150 * this.dpiScale;
			strengthItemList.y = ( 1500 + insertOffset ) * this.dpiScale;
			
			identifyTitle.x = 20 * this.dpiScale;
			identifyTitle.y = ( 1740 + insertOffset ) * this.dpiScale;
			identifyLabel.x = 150 * this.dpiScale;
			identifyLabel.y = ( 1740 + insertOffset ) * this.dpiScale;
			
			identifyItemList.x = 150 * this.dpiScale;
			identifyItemList.y = ( 1740 + insertOffset ) * this.dpiScale;
			
			imageTitle.x = 20 * this.dpiScale;
			imageTitle.y = ( 1860 + insertOffset ) * this.dpiScale;
			imageLabel.x = 190 * this.dpiScale;
			imageLabel.y = ( 1860 + insertOffset ) * this.dpiScale;
		}
		
		/**
		 * 设置详细数据 
		 * @param weaponVo 武器数据
		 * 
		 */		
		public function setBowGunData( weaponVo:BaseBowGunWeaponVo ):void
		{
			setData( weaponVo );
			_isLimitBreak = weaponVo.limitBreakPrice > 0;
			addAttackLabel.text = "+" + weaponVo.addAttack;
			reloadSpeedLabel.text = WeaponUtil.getBowGunReloadText( weaponVo.reloadSpeed );
			reactionLabel.text = WeaponUtil.getBowGunReactionText( weaponVo.reaction );
			offsetLabel.text = WeaponUtil.getBowGunOffsetText( weaponVo.offsetDirection, weaponVo.offsetLevel );
	
			var bullet3Arr:Array = [ "通", "贯", "散", "徹", "扩" ];
			var bullet2Arr:Array = [ "回", "毒", "麻", "睡", "减" ];
			var bullet1Arr:Array = [ "火", "水", "雷", "冰", "龙", "捕", "染", "鬼", "硬", "斩" ];
			var i:int;
			var len:int;
			
			for ( i = 0; i < 5; i ++ )
			{
				( bulletLabelVec[ i ] as Label ).text = bullet3Arr[ i ] + " " + 
					WeaponUtil.getCarryBulletText( weaponVo.carryBullet[ i * 3 ] ) + " / " +
					WeaponUtil.getCarryBulletText( weaponVo.carryBullet[ i * 3 + 1 ] ) + " / " +
					WeaponUtil.getCarryBulletText( weaponVo.carryBullet[ i * 3 + 2 ] );
			}
			
			( bulletLabelVec[ 5 ] as Label ).text = "竜       " + 
				WeaponUtil.getCarryBulletText( weaponVo.carryBullet[ 15 ] );
	
			for ( i = 6; i < 11; i ++ )
			{
				( bulletLabelVec[ i ] as Label ).text = '<font color="#' + WeaponUtil.bulletData[ 16 + ( i - 6 ) * 2 ].color.toString(16) + '">' + 
					bullet2Arr[ i - 6 ] + " </font>" + 
					WeaponUtil.getCarryBulletText( weaponVo.carryBullet[ 16 + ( i - 6 ) * 2 ] ) + " / " +
					WeaponUtil.getCarryBulletText( weaponVo.carryBullet[ 16 + ( i - 6 ) * 2 + 1 ] );
			}
			
			( bulletLabelVec[ 11 ] as Label ).text = '<font color="#' + WeaponUtil.bulletData[ 26 ].color.toString(16) + '">爆    </font>' + 
				WeaponUtil.getCarryBulletText( weaponVo.carryBullet[ 26 ] );
			
			for ( i = 12; i < 22; i ++ )
			{
				( bulletLabelVec[ i ] as Label ).text = '<font color="#' + WeaponUtil.bulletData[ 27 + ( i - 12 ) ].color.toString(16) + '">' + 
					bullet1Arr[ i - 12 ] + " </font>" + 
					WeaponUtil.getCarryBulletText( weaponVo.carryBullet[ 27 + ( i - 12 ) ] );
			}
			
			addAttackPriceLabel.text = weaponVo.addAttackPrice + "z";
			otherPriceLabel.text = weaponVo.otherPrice + "z";
			ratioMirrorPriceLabel.text = weaponVo.ratioMirrorPrice + "z";
			limitBreakPriceLabel.text = _isLimitBreak ? weaponVo.limitBreakPrice + "z" : "不能限解";
		}
		
		/**
		 * identifyItem皮肤 
		 * @return 
		 * 
		 */		
		protected function specialBulletRenderFactroy():IListItemRenderer
		{
			var renderer:DefaultListItemRenderer = ItemUtil.commonSimpleItem( 2, 10 );
			return renderer;
		}
		
		//-----------------------------
		// events
		//-----------------------------
		
		//-----------------------------
		// dispose
		//-----------------------------
		
		/**
		 * 析构函数 
		 * 
		 */		
		override public function dispose():void
		{
			super.dispose();
			addAttackTitle.dispose(); addAttackTitle = null;
			addAttackLabel.dispose(); addAttackLabel = null;
			reloadSpeedTitle.dispose(); reloadSpeedTitle = null;
			reloadSpeedLabel.dispose(); reloadSpeedLabel = null;
			reactionTitle.dispose(); reactionTitle = null;
			reactionLabel.dispose(); reactionLabel = null;
			offsetTitle.dispose(); offsetTitle = null;
			offsetLabel.dispose(); offsetLabel = null;
			specialBulletTitle.dispose(); specialBulletTitle = null;
			specialBulletLabel.dispose(); specialBulletLabel = null;
			bulletTitle.dispose(); bulletTitle = null;
			addAttackPriceTitle.dispose(); addAttackPriceTitle = null;
			addAttackPriceLabel.dispose(); addAttackPriceLabel = null;
			otherPriceTitle.dispose(); otherPriceTitle = null;
			otherPriceLabel.dispose(); otherPriceLabel = null;
			ratioMirrorPriceTitle.dispose(); ratioMirrorPriceTitle = null;
			ratioMirrorPriceLabel.dispose(); ratioMirrorPriceLabel = null;
			limitBreakPriceTitle.dispose(); limitBreakPriceTitle = null;
			limitBreakPriceLabel.dispose(); limitBreakPriceLabel = null;
			
			if ( _listDataSpecialBullet )
			{
				_listDataSpecialBullet.removeAll();
				_listDataSpecialBullet = null;
			}
			
			specialBulletList.dispose();
			specialBulletList = null;
			
			var len:int = bulletLabelVec.length;
			
			for ( var i:int = 0; i < len; i ++ )
			{
				( bulletLabelVec[ i ] as Label ).dispose();
				bulletLabelVec[ i ] = null;
			}
		}
		
		//-----------------------------
		// construction
		//-----------------------------
		
		/**
		 * 构造函数
		 *
		 */
		public function BaseBowGunWeaponDetailView()
		{
			super();
			imageY = 1860;
		}
	}
}